import base64
import time


encoded_id = "b0FDZFg1T3FNYzFoRG1xRzdTV2dvanY3WVk1QTI5MjYxMTYz"
decoded_id = base64.b64decode(encoded_id).decode('utf-8')
print(decoded_id)  # 输出: o@CX5Fa2mcLTE2kn4jZPQYSpAGk029258418


from datetime import datetime

# 定义目标日期
target_date = datetime(2025, 8, 20)

# 获取当前日期时间
current_date = datetime.now()

# 计算时间差
time_difference = current_date - target_date

# 转换为分钟数
minutes_difference = int(time_difference.total_seconds() / 60)

print(f"当前时间: {current_date}")
print(f"目标时间: {target_date}")
print(f"相距分钟数: {minutes_difference} 分钟")

start_time = 29260313 + minutes_difference

# exit()






def send_msg(msg):
    import requests
    import json

    url = "https://open.feishu.cn/open-apis/bot/v2/hook/5f141a68-35cf-4430-9396-ba41864f7368"

    payload = json.dumps({
        "msg_type": "text",
        "content": {
            "text": str(msg)
        }
    })
    headers = {
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'Content-Type': 'application/json',
        'Accept': '*/*',
        'Host': 'open.feishu.cn',
        'Connection': 'keep-alive'
    }

    response = requests.request("POST", url, headers=headers, data=payload)

    print(response.text)

# send_msg("机器人启动")
import base64

for i in range(20000):
    start_time += 1
    decoded_id = "oACdX5OqMc1hDmqG7SWgojv7YY5A"+str(start_time)
    encoded_id = base64.b64encode(decoded_id.encode('utf-8')).decode('utf-8')
    print(encoded_id)  # 输出: b0FDZFg1RmEybWNMVEUya240alpQWVNwQUdrMDI5MjU4NDE4
    print(start_time)


    while 1:
        import requests
        import json

        url = "https://fdsaas.hulasports.com/api/orderlists/get/book"
        import datetime

        # 获取明天0点的时间戳（毫秒）
        tomorrow_zero = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(
            days=1)
        timestamp_ms = int(tomorrow_zero.timestamp() * 1000)

        payload = json.dumps({
            "orderDateNum": timestamp_ms,
            "_venue": "637a13cd7ada9d492226d8a5",
            "_item": "637a13162ff0d406769d00d1",
            "passBaseOn": "start",
            "showLine": "row",
            "showPassTime": False,
            "_org": "636b6b04c2b591497458a198",
            "delayMins": 10,
            "_member": "688326fcb4449d2d65e262a8"
        })
        headers = {
            'appId': 'wx9cbd5e3ea332b83b',
            'memberId': '688326fcb4449d2d65e262a8',
            'token': '6DaD67m604',
            'openid': encoded_id,
            'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
            'content-type': 'application/json',
            'Accept': '*/*',
            'Host': 'fdsaas.hulasports.com',
            'Connection': 'keep-alive'
        }

        response = requests.request("POST", url, headers=headers, data=payload)

        print(response.text)

        if "未登录或登录过期" in response.text:
            break
        else:
            num = 0
            for data in response.json()['data']["booking_array"]:
                for data_hours in data['booking_infos']:
                    if data_hours["startDateHours"] in [19,20,21]:
                        if data_hours["state"]["state"] == "可预订":
                            s = f"{data_hours['startDate']}~{data_hours['endDate']}点，{data_hours['fieldName']}有场地了"
                            print(s)
                            send_msg(s)
                            num += 1
            if num > 0:
                send_msg("有刷新出场地，刷新先暂停3分钟")
                time.sleep(3*60)



        time.sleep(10)
